package com.woniuxy.woniuticket.moviemodule.service.impl;

import com.woniuxy.woniuticket.moviemodule.dao.CinemaMoviesDAO;
import com.woniuxy.woniuticket.moviemodule.pojo.ScheduleMsg;
import com.woniuxy.woniuticket.moviemodule.service.MovieinfoService;
import com.woniuxy.woniuticket.pojo.CinemaMovies;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * Created by Wu xianbo on 2019/6/11
 * 电影信息service实现类
 */

@Service
public class MovieinfoServiceImpl implements MovieinfoService {

    @Autowired
    private CinemaMoviesDAO cinemaMoviesDAO;

    //通过电影id获取电影详情
    @Override
    public CinemaMovies findMovieByMovieId(Integer id) {
        return cinemaMoviesDAO.selectByPrimaryKey(id);
    }

    @Override
    public int insertMovie(CinemaMovies movies) {
        return cinemaMoviesDAO.insertSelective(movies);
    }

    @Override
    public List<CinemaMovies> queryMovie(Integer page, Integer limit) {
        return cinemaMoviesDAO.queryAllMovie(page,limit);
    }

//    @Override
//    public List<CinemaMovies> queryMovie() {
//        return cinemaMoviesDAO.queryAllMovie();
//    }

    @Override
    public int delMovie(Integer[] moviesIds) {
        return cinemaMoviesDAO.delMovie(moviesIds);
    }

    @Override
    public int editMovie(CinemaMovies movies) {
        return cinemaMoviesDAO.editMovie(movies);
    }

    /**
     * 查询热点信息
     * @return
     */
    @Override
    public List<CinemaMovies> queryAllSchedule1() {
        Calendar cal = Calendar.getInstance();//使用默认时区和语言环境获得一个日历。
        cal.add(Calendar.DAY_OF_MONTH, +1);//取当前日期的后一天.
        //通过格式化输出日期
        java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String date=format.format(Calendar.getInstance().getTime());
        java.text.SimpleDateFormat format12 = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String date1=format12.format(cal.getTime());
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss");
        Date date10=null;
        Date date11=null;
        //必须捕获异常

        try
        {
            date10=simpleDateFormat.parse(date);
            date11=simpleDateFormat.parse(date1);
        }
        catch(ParseException px)
        {
            px.printStackTrace();
        }
        System.out.println(date10);
        return cinemaMoviesDAO.querySchedule1(date10,date11);
    }
}
